﻿// ManualControlDlg.cpp: 实现文件
//

#include "pch.h"
#include "ProjectAA.h"
#include "ManualControlDlg.h"
#include "afxdialogex.h"


// CManualControlDlg 对话框

IMPLEMENT_DYNAMIC(CManualControlDlg, CDialogEx)

CManualControlDlg::CManualControlDlg(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_DIALOG_CONTROL, pParent)
{

}

CManualControlDlg::~CManualControlDlg()
{
}

void CManualControlDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_STATIC_POS1, m_staticTableZ);
}


BEGIN_MESSAGE_MAP(CManualControlDlg, CDialogEx)
	ON_BN_CLICKED(IDC_BUTTON_LIGHT_ON, &CManualControlDlg::OnBnClickedButtonLightOn)
	ON_BN_CLICKED(IDC_BUTTON1, &CManualControlDlg::OnBnClickedButton1)
	ON_BN_CLICKED(IDC_BUTTON2, &CManualControlDlg::OnBnClickedButton2)
	ON_BN_CLICKED(IDC_BUTTON23, &CManualControlDlg::OnBnClickedButton23)
	ON_BN_CLICKED(IDC_BUTTON24, &CManualControlDlg::OnBnClickedButton24)
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_BUTTON26, &CManualControlDlg::OnBnClickedButton26)
	ON_BN_CLICKED(IDC_BUTTON25, &CManualControlDlg::OnBnClickedButton25)
	ON_BN_CLICKED(IDC_BUTTON27, &CManualControlDlg::OnBnClickedButton27)
	ON_BN_CLICKED(IDC_BUTTON29, &CManualControlDlg::OnBnClickedButton29)
	ON_BN_CLICKED(IDC_BUTTON28, &CManualControlDlg::OnBnClickedButton28)
END_MESSAGE_MAP()


// CManualControlDlg 消息处理程序


BOOL CManualControlDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	SetTimer(TIMER_CONTROL_AXIS_POS, 500, NULL);

	return TRUE;  // return TRUE unless you set the focus to a control
				  // 异常: OCX 属性页应返回 FALSE
}


void CManualControlDlg::OnCancel()
{
	KillTimer(TIMER_CONTROL_AXIS_POS);

	CDialogEx::OnCancel();
}


void CManualControlDlg::OnBnClickedButtonLightOn()
{
	if(gSystemMgr.Y21 == FALSE)
		gSystemMgr.m_cIo.SetOutputIo(21, ON);
	else
		gSystemMgr.m_cIo.SetOutputIo(21, OFF);
}


void CManualControlDlg::OnBnClickedButton1()
{
	gSystemMgr.m_cIo.SetOutputIo(0, ON);
	gSystemMgr.m_cIo.SetOutputIo(1, OFF);
}


void CManualControlDlg::OnBnClickedButton2()
{
	gSystemMgr.m_cIo.SetOutputIo(1, ON);
	gSystemMgr.m_cIo.SetOutputIo(0, OFF);
}


void CManualControlDlg::OnBnClickedButton23()
{
	gSystemMgr.m_cIo.SetOutputIo(3, ON);
	gSystemMgr.m_cIo.SetOutputIo(2, OFF);
}


void CManualControlDlg::OnBnClickedButton24()
{
	gSystemMgr.m_cIo.SetOutputIo(2, ON);
	gSystemMgr.m_cIo.SetOutputIo(3, OFF);
}


void CManualControlDlg::OnTimer(UINT_PTR nIDEvent)
{
	if (nIDEvent == TIMER_CONTROL_AXIS_POS)
	{
		CString cstr;
		cstr.Format(L"%d", gSystemMgr.m_vCMotor[M_CHART_Z].m_nCurPositon);
		m_staticTableZ.SetWindowTextW(cstr);
	}

	CDialogEx::OnTimer(nIDEvent);
}




void CManualControlDlg::OnBnClickedButton26()
{
	gSystemMgr.m_cIo.SetOutputIo(26, ON);
	gSystemMgr.m_cIo.SetOutputIo(27, ON);
	gSystemMgr.m_cIo.SetOutputIo(29, ON);

	if (1) {
		char ch[20];
		sprintf(ch, "set01 %d", gSystemMgr.LightSet);
		gSystemMgr.m_cLight.send_data((BYTE *)ch, strlen(ch));
		Sleep(50);
		sprintf(ch, "set02 %d", gSystemMgr.LightSet);
		gSystemMgr.m_cLight.send_data((BYTE *)ch, strlen(ch));
		Sleep(50);
		sprintf(ch, "set03 %d", gSystemMgr.LightSet);
		gSystemMgr.m_cLight.send_data((BYTE *)ch, strlen(ch));
		Sleep(50);
		sprintf(ch, "set04 %d", gSystemMgr.LightSet);
		gSystemMgr.m_cLight.send_data((BYTE *)ch, strlen(ch));
	}
	//gSystemMgr.m_cLight.send_data((BYTE *)"set01 21", 8);
	//gSystemMgr.m_cLight.send_data((BYTE *)"set02 21", 8);
	//gSystemMgr.m_cLight.send_data((BYTE *)"set03 21", 8);
	//gSystemMgr.m_cLight.send_data((BYTE *)"set04 21", 8);
}


void CManualControlDlg::OnBnClickedButton25()
{
	gSystemMgr.m_cIo.SetOutputIo(26, OFF);
	gSystemMgr.m_cIo.SetOutputIo(27, OFF);
	gSystemMgr.m_cIo.SetOutputIo(29, OFF);

	gSystemMgr.m_cLight.send_data((BYTE *)"set01 0", 7);
	Sleep(50);
	gSystemMgr.m_cLight.send_data((BYTE *)"set02 0", 7);
	Sleep(50);
	gSystemMgr.m_cLight.send_data((BYTE *)"set03 0", 7);
	Sleep(50);
	gSystemMgr.m_cLight.send_data((BYTE *)"set04 0", 7);
}


void CManualControlDlg::OnBnClickedButton27()
{
	if (gSystemMgr.PowerFlag_2 == 0)
		gSystemMgr.PowerFlag_2 = 1;
	else
		gSystemMgr.PowerFlag_2 = 0;
}


void CManualControlDlg::OnBnClickedButton29()
{
	gSystemMgr.m_cIo.SetOutputIo(25, ON);
	gSystemMgr.m_cIo.SetOutputIo(28, ON);

	if (1) {
		char ch[20];
		sprintf(ch, "set05 %d", gSystemMgr.LightSet_IR);
		gSystemMgr.m_cLight.send_data((BYTE *)ch, strlen(ch));
		Sleep(50);
		sprintf(ch, "set06 %d", gSystemMgr.LightSet_IR);
		gSystemMgr.m_cLight.send_data((BYTE *)ch, strlen(ch));
		Sleep(50);
		sprintf(ch, "set07 %d", gSystemMgr.LightSet_IR);
		gSystemMgr.m_cLight.send_data((BYTE *)ch, strlen(ch));
		Sleep(50);
		sprintf(ch, "set08 %d", gSystemMgr.LightSet_IR);
		gSystemMgr.m_cLight.send_data((BYTE *)ch, strlen(ch));

	}
}


void CManualControlDlg::OnBnClickedButton28()
{
	gSystemMgr.m_cIo.SetOutputIo(25, OFF);
	gSystemMgr.m_cIo.SetOutputIo(28, OFF);

	gSystemMgr.m_cLight.send_data((BYTE *)"set05 0", 7);
	Sleep(50);
	gSystemMgr.m_cLight.send_data((BYTE *)"set06 0", 7);
	Sleep(50);
	gSystemMgr.m_cLight.send_data((BYTE *)"set07 0", 7);
	Sleep(50);
	gSystemMgr.m_cLight.send_data((BYTE *)"set08 0", 7);
}
